<?php

class ProjectController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $this->view->title = "My Project";
                $this->view->headTitle($this->view->title);
        
                $project = new Application_Model_DbTable_Project();
                $where = "1=1";
                $order = "id desc";
                $this->view->project = $project->fetchAll($where,$order);
    }

    public function editAction()
    {
		$this->view->title = "Edit project";
		$this->view->headTitle($this->view->title);
        
        $form = new Application_Form_Project();
        $form->submit->setLabel(' 保 存 ');
        $this->view->form = $form;
        
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $id = (int)$form->getValue('id');
                $title = $form->getValue('title');
                $type = $form->getValue('type');
                $project = new Application_Model_DbTable_Project();
                $project->updateProject($id, $title,$type);
                
                 //$form->submit->setLabel('Saved');
                $this->_helper->redirector('index');
            } else {
                $form->populate($formData);
            }
        } else {
            $id = $this->_getParam('id', 0);
            if ($id > 0) {
                $project = new Application_Model_DbTable_Project();
                $form->populate($project->getProject($id));
            }
        }
    }


}



